<template>
  <view class="main">
    <u-navbar :background="{ backgroundColor: 'rgb(61, 95, 255)' }" :title="title" back-icon-color="#fff"
      title-color="#fff">
      <u-image slot="right" width="40" height="40" src="/static/image/filter.png" @click="goSearch" class="u-m-r-20" />
    </u-navbar>

    <!-- 筛选 -->
    <div class="city-box">
      <customerSearch isCountyName="countyStr" isCountyId="countyNo" isCustomerName="customerName"
        isCustomerId="mineCode" mineUrl="/cjt/common/getCustomerList" countyUrl="/alarm/common/getCountys"
        :getSearchData="searchData" @searchList="searchList" :isCode="true"></customerSearch>
        <!-- <u-input v-model="searchData.customerStr" placeholder="请选择煤矿" type="select" @click="cityShow = true"
            :select-open="cityShow" /> -->
        <div class="city-input">
        <u-search placeholder="工作面名称" v-model="searchData.name" shape="round" bg-color="#fff" height="80"
          :show-action="true" :animation="true" :input-style="{ marginLeft: '20rpx' }" :search-icon="searchSrc"
          placeholder-color="#999999" :action-style="{
      color: '#3D5FFF',
      fontSize: '14px',
      fontWeight: '400',
    }" @search="handleSearch" @custom="handleSearch" @change="handleSearch"></u-search>
      </div>
    </div>

    <div class="mine-num">
      工作面数量
      <span class="mine-num-val">{{ gzmTotal }}</span>
    </div>

    <scroll-view style="height: 200px;" :scroll-y="true" class="u-flex-1 of-hide" refresher-enabled="true" :refresher-triggered="triggered"
      :refresher-threshold="50" refresher-background="#F5F5F5" @refresherrefresh="onRefresh"
      @scrolltolower="onScrollToLower">
      <view class="list-item" v-for="(item, index) in listData" :key="index" @click="toDeails(item)">
        <div>
          <span class="zcsc" :class="item.currentStatusName==='正常'?'zcColor':item.currentStatusName==='暂停'?'ztColor':item.currentStatusName==='完工'?'wgColor':'wqColor'">{{ item.currentStatusName }}</span>
        </div>

        <div class="u-p-20">
          <div>
            <span class="list-name">{{ item.name }}</span>
            <span class="list-qu m-l-10">{{ item.customerName }}</span>
          </div>

          <div class="u-m-t-20 flex">
            <span class="tag-box tag-box1">
              <span class="tag-item" v-if="searchData.type==='0'">{{ item.drivingMethodName }}</span>
              <span class="tag-item" v-else>{{ item.coalTechName }}</span>
            </span>
            <span class="tag-box tag-box2" v-if="searchData.type==='0'">
              <span class="tag-item">{{ item.typeDetailName }}</span>
            </span>
            <span class="tag-box tag-box3" v-if="item.isIntelligentWorkFaceName">
              <span class="tag-item">{{ item.isIntelligentWorkFaceName==='是'?'智能':'' }}</span>
            </span>
            <!-- <span class="tag-box tag-box4">
              <span class="tag-item">炮掘</span>
            </span>
            <span class="tag-box tag-box5">
              <span class="tag-item">其他</span>
            </span> -->
          </div>

          <div class="sjcd" v-if="searchData.type==='0'">
            <div>设计长度：{{ item.designLen }}</div>
            <div class="sjcd-lj">累计总进尺：{{ item.accruedAllFootage }}</div>
          </div>
          <div class="sjcd" v-else>
            <div>走向长度：{{ item.designLen }}</div>
            <div class="sjcd-lj">累计总推进：{{ item.accruedAllFootage }}</div>
          </div>
          <div class="progress-box">
            <div class="progress-line"><u-line-progress :percent="Number(item.finish) > 100 ? 100 : Number(item.finish)" :show-percent="false"></u-line-progress></div>
            <div class="progress-num">{{Number(item.finish) > 100 ? '100%' : item.finish+'%'}}</div>
          </div>

        </div>

      </view>
      <template v-if="!showEmpty">
        <view class="c-empty p-absolute-center">
          <u-empty text="抱歉，暂无相关数据~" :src="require('@/static/image/empty.png')"></u-empty>
        </view>
      </template>
      <view class="p-t-10 p-b-10" v-else>
        <u-loadmore :status="status" />
      </view>
    </scroll-view>
    <u-picker mode="selector" v-model="cityShow" :range="customerList" range-key="label" @confirm="cityConfirm"></u-picker>
  </view>
</template>

<script>
  import customerSearch from '@/pages/components/customerSearch.vue'
export default {
  components: { customerSearch },
  data () {
    return {
      searchSrc: require("@/static/image/search.png"),
      emitEvent: 'cjt_mineList',
      listData: [],
      total: '',
      searchData: {
        countyNo: "",
        countyStr: "所有区县",
        customerStr: "",
        customerNo: "",
        customerName: "",
        customerCode: "",
        pageSize: 20,
        pageNumber: 1,
        type:'0',
        coalTech:'',
        isIntelligent:'',
        drivingMethod:'',
        currentStatus:'',
        currentStatusCopye:'',
        typeDetail:'',
        coalTech:''
      },
      triggered: false,
      showEmpty: true,
      status: "loading",
      customerList:[],
      cityShow:false,
      customerNo:'',
      gzmTotal:0,
      title:''
    };
  },
  onLoad (options) {
    let item = JSON.parse(options.data)
    this.searchData.type=item.type
    if(item.type==='1'&&item.drivingMethod!=='999'&&item.drivingMethod!=='009'){
      this.searchData.coalTech = item.drivingMethod
      this.title = '回采工作面列表'
    }else if(item.type==='0'&&item.drivingMethod!=='999'&&item.drivingMethod!=='009'){
      this.searchData.drivingMethod=item.drivingMethod
      this.title = '掘进工作面列表'
    }
    this.searchData.currentStatus=item.currentStatus
    this.searchData.currentStatusCopye = item.currentStatus
    if(item.drivingMethod==='999'||item.drivingMethod==='009'){
      this.searchData.isIntelligent='0'
      this.searchData.drivingMethod=''
    }
    if (getApp().globalData.userInfo.superviseLevel !== "40") {
      this.searchData.countyNo = getApp().globalData.userInfo.countyNo;
    }else{
      this.searchData.countyNo = item.countyNo
    }
    this.searchData.customerNo = item.customerNo
    this.searchData.mineCode = item.customerNo
    this.searchData.customerName = item.customerName
    // this.getCustomerList()
    this.getList();

    uni.$on(this.emitEvent, res => {
      this.searchData = {
        ...this.searchData,
        ...res,
        pageNumber: 1
      }
      this.getList()
    })
  },
  onUnload () {
    // 清除监听
    uni.$off(this.emitEvent);
  },
  methods: {
    cityConfirm (index) {
      this.searchData.customerStr = this.customerList[index].label
      this.searchData.customerNo = this.customerList[index].code
      this.getList()
    },
    getCustomerList(){
      this.$get('/cjt/common/getCustomerList?countyNo='+this.searchData.countyNo).then(res=>{
        this.customerList = res.body
      })
    },
    handleSearch () {
      if (this.searchTimer) {
        clearTimeout(this.searchTimer);
      }
      this.searchTimer = setTimeout(async () => {
        this.getList();
      }, 300);
    },
    goSearch () {
      const form = {
        ...this.searchData,
      };
      uni.navigateTo({
        url: `./screen?form=${JSON.stringify(form)}&emitEvent=${this.emitEvent}`,
      });
    },
    toDeails (item) {
      item.type = this.searchData.type
      uni.navigateTo({
        url: `./detail?item=${JSON.stringify(item)}`,
      });
    },
    searchList (e) {
      this.searchData = Object.assign(this.searchData, e);
      this.getList();
    },
    init () {
      this.searchData.pageNumber = 1;
      this.status = "loading";
      this.showEmpty = true;
    },
    onRefresh () {
      if (this.Isfreshing) return;
      this.Isfreshing = true;
      if (!this.triggered) {
        // 保证刷新状态下，triggered为true
        this.triggered = true;
        this.init();
        this.getList();
        setTimeout(() => {
          this.triggered = false; // 触发onRestore，关闭刷新图标
          this.Isfreshing = false;
        }, 1200);
      }
    },
    onScrollToLower () {
      if (this.status === "loading") {
        this.searchData.pageNumber++;
        this.getList();
      }
    },
    async getList () {
      this.$set(this.searchData, "customerNo", this.searchData.mineCode);
      const res = await this.$post("/engineering/dataList", this.searchData);
      if (res && res.body.content) {
        this.gzmTotal=res.body.total
        this.listData = this.searchData.pageNumber === 1 ? res.body.content : this.listData.concat(res.body.content);
        // 到底了
        if (res.body.content.length < this.searchData.pageSize) {
          this.status = "nomore";
        }
        // 数据空
        if (this.searchData.pageNumber === 1 && this.listData && this.listData.length === 0) {
          this.showEmpty = false;
        } else {
          this.showEmpty = true;
        }
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.list-item {
  box-shadow: 0 0 10px 0 rgba(1, 72, 51, 0.2) !important;
  border-radius: 6px !important;
  position: relative;
  margin: 10px;

  .zcsc {
    min-width: 60px;
    border-radius: 0 6px 6px 0;
    color: #fff;
    font-size: 12px;
    padding: 5px 10px;
    margin-top: 10px;
    text-align: center;
    display: inline-block
  }
  .zcColor{
    background: #4ADCAC;
  }
  .ztColor{
    background: #D29E08;
  }
  .wgColor{
    background: #20b6fa;
  }
  .wqColor{
    background: #999999;
  }
  .list-name {
    font-size: 16px;
    font-weight: 500
  }

  .list-qu {
    color: rgb(102, 102, 102)
  }

  .tag-box {
    display: flex;
    // width: 40px;
    margin-right: 10px;
    border-radius: 3px;
    padding:2px 5px;
    .tag-item {
      display: block;
      height: 16px;
      width: 100%;
      text-align: center;
      line-height: 16px;
      font-size: 14px;
    }

    img {
      display: block;
      width: 16px;
      height: 16px;
      margin: 0
    }
  }

  .tag-box1 {
    background: rgba(47, 89, 242, 0.2);

    .tag-item {
      color: rgb(46, 88, 244)
    }
  }

  .tag-box2 {
    background: rgba(43, 208, 137, 0.2);

    .tag-item {
      color: rgb(43, 208, 137)
    }
  }

  .tag-box3 {
    background: rgba(255, 176, 56, 0.2);

    .tag-item {
      color: rgb(255, 176, 56)
    }
  }

  .tag-box4 {
    background: rgba(56, 166, 249, 0.2);

    .tag-item {
      color: rgb(56, 166, 249)
    }
  }

  .tag-box5 {
    background: rgba(102, 102, 102, 0.2);

    .tag-item {
      color: rgb(102, 102, 102)
    }
  }
}

.text-center {
  text-align: center
}

.mine-num {
  text-align: center;
  height: 66px;
  background: #fff;
  line-height: 60px;
  color: #fff;
  background: url('/static/image/cjt/cjnxzc.png');
  background-size: 100% 100%;
  margin: 10px;
  margin-top: 0;

  .mine-num-val {
    font-size: 30px;
    margin-left: 10px;
    position: relative;
    top: 2px;
  }
}


.city-box {
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: center;
  .uni-input-placeholder{
    margin-left: 20px;
  }
  .uni-input-input{
    margin-left: 20px;
  }
  .u-input{
  flex: none;
    background: #fff;
    border-radius: 15px;
    margin: 10px;
}

 /deep/ .u-input__right-icon{
    margin-right: 15px;
  }
  .city-input {
    background: #fff;
    margin: 10px;
  }
}

.sjcd{
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: rgb(102, 102, 102);
  margin-top: 20px;
  .sjcd-lj{
    padding-right: 3em
  }
}

.progress-box{
  display: flex;
  margin-top: 5px;
  .progress-line{
    flex: 1
  }
  .progress-num{
    width: 3em;
    text-align: center
  }
}
/deep/ .uni-input-input{
  padding-left: 20px;
}
</style>
